|
1
|
|
|
import Helper from '../../src/Helper'; |
|
2
|
|
|
import InvalidInputError from '../../src/InvalidInputError'; |
|
3
|
|
|
|
|
4
|
|
|
const TestCasesResult = [ |
|
5
|
|
|
{ |
|
6
|
|
|
description: '1 = 1', |
|
7
|
|
|
number: 1, |
|
8
|
|
|
propositions: 1, |
|
9
|
|
|
expectedResult: '1', |
|
10
|
|
|
}, |
|
11
|
|
|
{ |
|
12
|
|
|
description: '1 = 001', |
|
13
|
|
|
number: 1, |
|
14
|
|
|
propositions: 3, |
|
15
|
|
|
expectedResult: '001', |
|
16
|
|
|
}, |
|
17
|
|
|
{ |
|
18
|
|
|
description: '7 = 111', |
|
19
|
|
|
number: 7, |
|
20
|
|
|
propositions: 3, |
|
21
|
|
|
expectedResult: '111', |
|
22
|
|
|
}, |
|
23
|
|
|
{ |
|
24
|
|
|
description: '7 = 000111', |
|
25
|
|
|
number: 7, |
|
26
|
|
|
propositions: 6, |
|
27
|
|
|
expectedResult: '000111', |
|
28
|
|
|
}, |
|
29
|
|
|
{ |
|
30
|
|
|
description: '8 = 1000', |
|
31
|
|
|
number: 8, |
|
32
|
|
|
propositions: 1, |
|
33
|
|
|
expectedResult: '1000', |
|
34
|
|
|
}, |
|
35
|
|
|
]; |
|
36
|
|
|
|
|
37
|
|
|
describe.each(TestCasesResult)( |
|
38
|
|
|
'Test dec2bin helper', |
|
39
|
|
|
({ description, number, propositions, expectedResult }) => { |
|
40
|
|
|
it(description, () => { |
|
41
|
|
|
const result = Helper.dec2bin(number, propositions); |
|
42
|
|
|
expect(result).toBe(expectedResult); |
|
43
|
|
|
}); |
|
44
|
|
|
} |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
describe('Test dec2bin helper', () => { |
|
48
|
|
|
it('Test if the method returns the exception if you dont pass an number', () => { |
|
49
|
|
|
function testWrongInput() { |
|
50
|
|
|
Helper.dec2bin(null); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
expect(testWrongInput).toThrowError(new Error('number isnt a number')); |
|
54
|
|
|
expect(testWrongInput).toThrowError(InvalidInputError); |
|
55
|
|
|
}); |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
const ErrorTestCases = [ |
|
59
|
|
|
{ |
|
60
|
|
|
description: 'test number with a null value', |
|
61
|
|
|
number: null, |
|
62
|
|
|
propositions: 1, |
|
63
|
|
|
expectedError: 'number isnt a number', |
|
64
|
|
|
}, |
|
65
|
|
|
{ |
|
66
|
|
|
description: 'test number with a string', |
|
67
|
|
|
number: 'not ok', |
|
68
|
|
|
propositions: 1, |
|
69
|
|
|
expectedError: 'number isnt a number', |
|
70
|
|
|
}, |
|
71
|
|
|
{ |
|
72
|
|
|
description: 'test propositions with a null value', |
|
73
|
|
|
number: 1, |
|
74
|
|
|
propositions: null, |
|
75
|
|
|
expectedError: 'propositions isnt a number', |
|
76
|
|
|
}, |
|
77
|
|
|
{ |
|
78
|
|
|
description: 'test propositions with a string', |
|
79
|
|
|
number: 1, |
|
80
|
|
|
propositions: 'not ok', |
|
81
|
|
|
expectedError: 'propositions isnt a number', |
|
82
|
|
|
}, |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
describe.each(ErrorTestCases)( |
|
86
|
|
|
'Test dec2bin helper exception test', |
|
87
|
|
|
({ description, number, propositions, expectedError }) => { |
|
88
|
|
|
it(description, () => { |
|
89
|
|
|
function testWrongInput() { |
|
90
|
|
|
Helper.dec2bin(number, propositions); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
expect(testWrongInput).toThrowError(new Error(expectedError)); |
|
94
|
|
|
expect(testWrongInput).toThrowError(InvalidInputError); |
|
95
|
|
|
}); |
|
96
|
|
|
} |
|
97
|
|
|
); |
|
98
|
|
|
|